//

//  menuEGAViewController.m

//  EGA_Archives_iOS

//

//  Created by gad on 1/6/56 BE.

//  Copyright (c) 2556 EGA. All rights reserved.

//

#import "EGAEmployeeInfo.h"

#import "EGAAppDelegate.h"

#import "menuEGAViewController.h"

#import "mainEGAViewController.h"

#import "arcAssignEGAViewController.h"

@interface menuEGAViewController ()

@end

@implementation menuEGAViewController

-(EGAAppDelegate*)appDelegate

{
    
    return  (EGAAppDelegate*)[[UIApplication sharedApplication] delegate];
    
}

NSString * role;

- (id)initWithStyle:(UITableViewStyle)style

{
    
    self = [super initWithStyle:style];
    
    if (self) {
        
        // Custom initialization
        
    }
    
    return self;
    
}

- (void)didReceiveMemoryWarning

{
    
    [super didReceiveMemoryWarning];
    
    // Dispose of any resources that can be recreated.
    
}

/*-(void)viewDidLoad
 
 {
 
 [super viewDidLoad];
 
 
 
 }*/

#pragma mark - Table view data source

- (NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection : (NSInteger) section{
    
    NSString *RoleName = self.appDelegate.employeeInfo.RoleName;
    
    role=RoleName;
    
    
    
    if (([role isEqualToString:@"admin"]) || (([role isEqualToString:@"secretary"])))
        
    {
        
        switch(section)
        
        {
                
                
                
            case 1:
                
                return 1;
                
                break;
                
            default:return 3;//4
                
                break;
                
        }
        
    }
    
    else  if (([role isEqualToString:@"viewer"]) )
        
    {
        
        switch(section)
        
        {
                
                
                
            case 0:
                
                return 3;//4
                
                break;
                
            default:return -1;
                
                break;
                
        }
        
        
        
    }
    
    else  if (([role isEqualToString:@"manager"]) )
        
    {
        
        switch(section)
        
        {
                
                
                
            case 1:
                
                return -1;//4
                
                break;
                
                
                
            default:return 3;
                
                break;
                
        }
        
    }
    
}



- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

{
    
    
    
    return 3;
    
}



-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    return 50;
    
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{
    
    if (([role isEqualToString:@"manager"]))
        
    {
        
        if (section==1) return 0; else return 50;
        
    }
    
    else return 50;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    static NSString *MyIdentifier = @"MyIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier : MyIdentifier];
    
    
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle reuseIdentifier : MyIdentifier];
        
    }
    
    
    
    cell.textLabel.textColor = [UIColor grayColor];
    
    cell.textLabel.font = [UIFont systemFontOfSize:22];
    
    cell.detailTextLabel.textColor = [UIColor lightGrayColor];
    
    switch (indexPath.section)
    
    {
            
            
            
        case 1:
            
            if (indexPath.row == 0)
                
            {
                
                cell.textLabel.text = @"มอบหมายสั่งการ";
                
                cell.detailTextLabel.text = @"";
                
                //cell.detailTextLabel.text = @"(0-0)";
                
            }
            
            break;
            
        default:
            
            if (indexPath.row == 0)//1
                
            {
                
                cell.textLabel.text = @"ยังไม่ดำเนินการ";
                
                cell.detailTextLabel.text = @"";
                
                //cell.detailTextLabel.text = @"(2-1)";
                
            }
            
            if (indexPath.row == 1)//2
                
            {
                
                cell.textLabel.text = @"ระหว่างดำเนินการ";
                
                cell.detailTextLabel.text = @"";
                
                //cell.detailTextLabel.text = @"(2-2)";
                
            }
            
            if (indexPath.row == 2)//3
                
            {
                
                cell.textLabel.text = @"ดำเนินการเรียบร้อย";
                
                cell.detailTextLabel.text = @"";
                
                //cell.detailTextLabel.text = @"(2-3)";
                
            }
            
            break;
            
            
            
    }
    
    return cell;
    
}



// Override to support conditional editing of the table view.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    // Return NO if you do not want the specified item to be editable.
    
    return YES;
    
}



- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 50)];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, tableView.bounds.size.width - 10, 18)];
    
    
    label.font = [UIFont systemFontOfSize:22];
    
    
    if (([role isEqualToString:@"admin"]) || (([role isEqualToString:@"secretary"])))
        
    {
        
        switch(section)
        
        {
                
            case 0:
                
                label.text= @"งานของฉัน";
                
                break;
                
            case 1:
                
                label.text= @"มอบหมาย / สั่งการ";
                
                break;
                
            case 2:
                
                label.text= @"ติดตาม";
                
                break;
                
            default:
                
                label.text= @"";
                
                break;
                
        } 
        
    } else
        
        if (([role isEqualToString:@"manager"]))
            
        {
            
            switch(section)
            
            {
                    
                case 0:
                    
                    label.text= @"งานของฉัน";
                    
                    break;
                    
                case 2:
                    
                    label.text= @"ติดตาม";
                    
                    break;
                    
                default:
                    
                    label.text= @"";
                    
                    break;
                    
            } 
            
        }
    
    
    
        else
            
        {
            
            if(section == 0)
                
            {
                
                label.text= @"งานของฉัน";
                
            }else 
                
                label.text= @"";
            
            
            
        }
    
    [label sizeToFit];
    
    label.textColor = [UIColor whiteColor];
    
    label.backgroundColor = [UIColor clearColor];
    
    
    
    [headerView addSubview:label];
    
    
    
    return headerView;
    
}



#pragma mark - Table view delegate



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    if (self.menuDelegate) {
        
        [self.menuDelegate menuController:self didSelectedMenuAtIndex:indexPath];
        
    }
    
}

@end

